package rig.com.util;

import java.util.concurrent.TimeUnit;

/**
 * @author MShaoJie
 * @create 2021/8/24 9:08
 **/
public class TimeUtil {
    private static volatile long currentTimeMillis;

    static {
        currentTimeMillis = System.currentTimeMillis();
        Thread deamon = new Thread(() -> {
            while (true) {
                currentTimeMillis = System.currentTimeMillis();
                try {
                    TimeUnit.MILLISECONDS.sleep(1);
                } catch (InterruptedException e) {
                }
            }
        });
        deamon.setName("time-tick-thread");
        deamon.setDaemon(true);
        deamon.start();
    }

    public static long currentTimeMillis() {
        return currentTimeMillis;
    }

}
